package com.cq.hd.admin.controller;

import com.cq.hd.admin.annotation.RequiresPermissionsDesc;
import com.cq.hd.admin.biz.AdminBusinessBiz;
import com.cq.hd.admin.po.TbBusinessAdminUserPo;
import com.cq.hd.admin.vo.AdminBusinessInfoVo;
import com.cq.hd.common.enums.ResponseEnums;
import com.cq.hd.common.response.Result;
import com.cq.hd.common.response.ResultGenerator;
import com.cq.hd.common.response.Throw;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "商家后台商家信息相关接口")
@Slf4j
@RestController
@RequestMapping("/admin/business")
public class AdminBusinessController extends BaseController {

    @Autowired
    private AdminBusinessBiz adminBusinessBiz;

    @ApiOperation(value = "商家信息")
    @ApiResponse(response = AdminBusinessInfoVo.class, code = 200, message = "接口返回对象参数")
    @RequiresPermissions("adminBusiness:business:info")
    @RequiresPermissionsDesc(menu = {"商家后台", "商家信息"}, button = "查询")
    @GetMapping("/info")
    public Result<AdminBusinessInfoVo> businessInfo() {
        TbBusinessAdminUserPo businessAdminUserPo = getBusinessAdminUser();
        if (businessAdminUserPo == null) {
            Throw.isBusinessException(ResponseEnums.BUSINESS_ACCESS_DENIED);
        }

        Long businessId = businessAdminUserPo.getBusinessId();
        Long appUserId = businessAdminUserPo.getAppUserId();
        if (businessId == null || businessId <= 0 || appUserId == null || appUserId <= 0) {
            Throw.isBusinessException(ResponseEnums.BUSINESS_ACCESS_DENIED);
        }

        return ResultGenerator.success(adminBusinessBiz.businessInfo(businessAdminUserPo));
    }

}
